package com.woniuxy01;

import java.sql.SQLOutput;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-07-29 14:11
 */
public class Test03 {
    public static void main(String[] args)  {
        try {
            Date date = stringToDate03("2000-a1-1");
            System.out.println(date);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println("over");
    }


    public static Date stringToDate03(String str){
        try {
            return stringToDate02(str);
        } catch (Exception e) {
            System.out.println("03处理异常，抛出异常，没有处理");
            throw new RuntimeException(e);
        }
    }

    public static Date stringToDate02(String str) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(str);
            return date;
        } catch (ParseException e) {
//            e.printStackTrace();
            System.out.println("02处理异常，抛出异常，没有处理");
            //将受查异常转成非受查异常，抛出异常,抛给方法的调用者
            throw new RuntimeException("stringToDatecu错误",e);
        }
    }

    public static Date stringToDate01(String str) {
        try {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(str);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("处理异常");
        }
        return null;
    }

    public void test06(){
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = df.parse("2000-a1-1");
            System.out.println(date);
        } catch (ParseException e) {
            System.out.println("日期格式错误无法转换");
        }
    }

    public void test05() {
        try {
            int num = new Scanner(System.in).nextInt();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("整数转换，出现异常，输入错误");
        }
    }

    private static void test04() {
        try {
            String str = null;
            str.equals("aaa");
//            int result=10/0;
            System.out.println("try结束");
        } catch (Exception e) {
//            System.out.println(e.getMessage());
            e.printStackTrace();
//            System.out.println("catch处理Exception异常");
        }
        System.out.println("程序结束");
    }

    private static void test03() {
        try {
//            Scanner sc = new Scanner(System.in);
//            sc.nextInt();

            String str = null;
//            str.equals("aaa");
            int[] a = {1, 2, 3};
            System.out.println(a[0]);
            System.out.println(a[1]);
            System.out.println(a[2]);
            System.out.println(a[3]);
            System.out.println("try结束");
        } catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
            System.out.println("catch两种异常异常同一处理");
        } catch (Exception e) {
            System.out.println("catch处理Exception异常");
        }
        System.out.println("程序结束");
    }

    private static void test02() {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入整数");
        int num = sc.nextInt();
        System.out.println("over");
    }

    private static void test01() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.parse("2000-1-q");
        System.out.println("over");
    }
}
